package me.zk.practice1.hw;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author zhangkai
 * @date 2023/8/7 13:05
 */
public class HWBJ58 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nums = Arrays.stream(scanner.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();

        int sum = Integer.parseInt(scanner.nextLine());

        int l = 0;
        int r = 0;
        int total = 0;
        int max = -1;
        for (int i = 0; i < nums.length; i++) {
            total += nums[i];
            if (total == sum) {
                max = Math.max(r-l+1,max);
            } else if (total > sum) {
                while (total > sum) {
                    total-=nums[l];
                    l++;
                }
            }
            r++;
        }
        System.out.println(max);
    }
}
